package cn.mengfly.testnrz.im.client.builder;

import cn.mengfly.testnrz.im.ProtoMsg;
import cn.mengfly.testnrz.im.client.ClientSession;
import cn.mengfly.testnrz.im.client.bean.User;

public class LoginMsgBuilder extends BaseBuilder {

    private final User user;

    public LoginMsgBuilder(User user, ClientSession session) {
        super(ProtoMsg.HeadType.LOGIN_REQUEST, session);
        this.user = user;
    }

    public ProtoMsg.Message build() {
        ProtoMsg.Message message = buildCommon(-1);
        ProtoMsg.LoginRequest.Builder lb =
                ProtoMsg.LoginRequest.newBuilder()
                        .setDeviceId(user.getDeviceId())
                        .setPlatform(user.getPlatType().ordinal())
                        .setToken(user.getToken())
                        .setUid(user.getUid());
        return message.toBuilder().setLoginRequest(lb).build();
    }

    public static ProtoMsg.Message buildLoginMsg(User user, ClientSession session) {
        return new LoginMsgBuilder(user, session).build();
    }

}
